package com.wyl.auth.config.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

/**
 * @Description
 * @Author WuYiLong
 * @Date 2024/2/15 17:14
 */
@ConditionalOnProperty(prefix = "minio",value = "enable",havingValue = "true")
@Configuration
public class MinioClientService implements InitializingBean {

    @Autowired
    private MinioProperty minioProperty;

    private static MinioClient minioClient;

    @Override
    public void afterPropertiesSet() throws Exception {
        minioClient = new MinioClient.Builder()
                .credentials(minioProperty.getAccessKey(), minioProperty.getSecretKey())
                .endpoint(minioProperty.getEndpoint())
                .build();
    }

    public static MinioClient createMinioClient() {
        Assert.notNull(minioClient,"minio客户端对象不能为空");
        return MinioClientService.minioClient;
    }




}